import $api from "@/api/index.js"
import $store from "@/store/index.js"
import {
	req
} from '@/utils/req.js';
export default {
	state: {
		pageActive: false,
		activeIndex: -1,
		tabList: [{
			title: '距离',
			id: 0,
		}, {
			title: '类型',
			id: 1,
		}, {
			title: '价格',
			id: 2
		}],
		demandTabList: [{
			title: '距离',
			id: 0,
		}, {
			title: '类型',
			id: 1,
		}, {
			title: '价格',
			id: 2
		}, {
			title: '订单类型',
			id: 3
		}],
		param: {
			page: 1,
			di_order: 0, // 1距离近 2距离远
			pr_order: 0, // 1价格高 2价格低
			type: 0,
			lat:'',
			lng: '',
			order_type: 0
		},
		list: {
			data: [],
			last_page: 1,
			current_page: 1
		},
		distanceList:[
			{label:'由近及远',value:1},
			{label:'由远及近',value:2}
		],
		priceList:[
			{label:'由高到低',value:2},
			{label:'由低到高',value:1}
		],
		orderType:[
			{label:'标准订单',value:1, type: 'service_count'},
			{label:'需求订单',value:2, type: 'demand_count'}
		],
		demandOrder:[
			{label:'全部',value:0},
			{label:'咨询单',value:1},
			{label:'一口价',value:2},
			{label:'家政公司',value:3}
		],
		skill: [],
		orderTypeIndex: 1
	},
	mutations: {
		async updatePoolItem(state, item) {
			let {
				key,
				val
			} = item
			state[key] = val
		}
	},
	actions: {
		async getWaitOrderList({
			commit,
			state
		}, param) {
			
			let d = ''
			if(state.orderTypeIndex == 1){
				d = await req.get("massage/app/IndexCoach/waitOrderList", param);
			} else if(state.orderTypeIndex == 2){
				d = await req.get("demand/app/coach/waitOrderList", param);
			}
			console.log(d)
			let oldList = state.list;
			let newList = d;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data)
				list = newList;
			}
			commit('updatePoolItem', {
				key: 'list',
				val: list
			})
		},
		async getTypeList({
			commit,
			state
		}, param) {
			// state.pageActive = true
			
			let d = await $api.pool.typeList(param)
			
			d.unshift({name: '全部', id: 0 ,children: [{name: '全部', id: 0}]})
			d.forEach(item => {
				item.children = item.children ? item.children : []
			})
			console.log(d)
			commit('updatePoolItem', {
				key: 'skill',
				val: d
			})
		}
	},
}
